<script type="text/javascript" SRC="/js/merchant/orders.js"></script>
<style>
	
	.bgc{background:#F2F8FD}
	.radiu{-webkit-border-radius: 5px;-moz-border-radius:5px;border-radius:5px;overflow: hidden;}
	.info-top{height:10px}
	.tab-li{ float:left; padding:0; cursor:pointer; background:url(/images/menu-li-bg.gif) no-repeat center top; width:92px; height:25px; line-height:25px; text-align:center; color:white}
	.tab-li-click{background:url(/images/menu-li-bg-hover.gif) no-repeat center top}
	.tab-li:hover{ background:url(/images/menu-li-bg-hover.gif) no-repeat center top}
	.info-header{width:100%;height:200px;background:url(/images/nav-bg.png) no-repeat center top;border-bottom:1px solid #CCC;position:relative}
	.info-header h3{text-indent:10px;}
	.info-content{}
	.info-content-body{border-top:1px solid #CCC;width:100%;clear:both;min-height: 200px;}
	.info-content-menu{width:100%;height:25px}
	.info-header-content{position:absolute;top:50px;left:10px;width:870px;border:1px solid #CCC;}
	.cell20{width:180px;height:25px;line-height:25px;display:inline-block;overflow:hidden;border-bottom:1px solid #CCC;margin:0px;border-right:1px solid #CCC;margin:0px;float:left}
	.cell30{width:253px;height:25px;line-height:25px;display:inline-block;overflow:hidden;border-bottom:1px solid #CCC;margin:0px;border-right:1px solid #CCC;margin:0px;margin:0px;float:left}
	.no-bottom{border-bottom:none}
	.no-right{border-right:none}
	.error{color:red}
	
.line1 {
	height: 25px;
	width: 100%;
	background: none repeat scroll 0 0 #FFFFFF;
	text-align:center;
}
.line1:hover, .line2:hover{
	background-color:#F2F8F9;
}

.line2 {
	height: 25px;
	width: 100%;
}

.orderCode:hover{
	cursor:pointer;
}
.tdCol1 {
    float: left;
    line-height: 25px;     
    width: 5%;
}
.tdCol2 {
    float: left;
    line-height: 25px;     
    width: 15%;
}
.tdCol3 {
    float: left;
    line-height: 25px;
    width: 10%;
}
.tdCol4 {
    float: left;
    line-height: 25px;
    width: 10%;
}
.tdCol5 {
    float: left;
    line-height: 25px;
    width: 10%;
}

.tdCol6 {
    float: left;
    line-height: 25px;
    width: 15%;
}
.tdCol7{
    float: left;
    line-height: 25px;
    width: 10%;
}
.tdCol8{
    float: left;
    line-height: 25px;
    width: 16%;
}

.cell2 {
float: left;
overflow: hidden;
height: 25px;
line-height: 25px;
text-align: center;
background: url("") repeat-y right top;
}

div.order-operation{
	margin-top:4px;margin-bottom:6px;
}
.editIcon{
	cursor:pointer;
}
.viewIcon{
	cursor:pointer;
}
.bold{
	font-weight:bold;
	font-style:none;
}
.batchProcess{
	margin-right:1px;
}
</style>
<script type="text/javascript">

var orderBackObj = "";
var orderBackCode = "";
$(function(){
	$('.toggleButton').click(function(){
		if($(this).attr("refstatus") != 1){
			$(".detailInfo").hide();
			$(this).attr("refstatus",1);
            $(this).html($(this).attr("fold"));
		}else{
			$(".detailInfo").show();
			$(this).attr("refstatus",0);
            $(this).html($(this).attr("unfold"));
		}
	});
	$("#messageDialog").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		buttons:{
					"OK":function(){
						$(this).dialog("close");
					}
				}
	});
	$("#checkPlanDialog").dialog({
		autoOpen:false,
		modal:true,
		width:500,
		show:"slide",
		buttons:{
					"OK":function(){
						submitBatch($(".batchProcess:[status=2]"),true);
						$(this).dialog("close");
					},
					"Cancel":function(){
						$(this).dialog("close");
						$('#statusDialog').dialog("open");
					}
				}
	});
	
	$("#orderBackConfirmDialog").dialog({
		autoOpen:false,
		modal:true,
		width:500,
		show:"slide",
		buttons:{
			"OK":function(){	
				$(this).dialog("close");			
				orderBackDo(orderBackObj,orderBackCode);
			},
			"Cancel":function(){
				$(this).dialog("close");						
			}
		}
	});
	
	$("#orderStopConfirmDialog").dialog({
		autoOpen:false,
		modal:true,
		width:500,
		show:"slide",
		buttons:{
			"OK":function(){	
				$(this).dialog("close");			
				orderStopDo(orderStopObj,orderStopCode);
			},
			"Cancel":function(){
				$(this).dialog("close");						
			}
		}
	});
	
	$("#statusDialog").dialog({
		autoOpen:false,
		modal:true,
		width:500,
		show:"slide",
		buttons:{
					"OK":function(){
						$(this).dialog("close");
					}
				}
	});
	
	$('#createTime').datepicker({
        changeMonth:true,
        changeYear:true,
        dateFormat:'yy-mm-dd'
    });
});
function checkAll(obj){
	if(jQuery (obj).attr("checked")=='checked'){
		jQuery ('.checked').attr('checked',true);
	}else{
	    jQuery ('.checked').attr('checked',false);
	}
}

function tabSelect(obj,status,underreview_status){
	if(underreview_status==undefined){
		underreview_status = 0;
	}
	clear();
	$('[name=status]').val(status);
	$('[name=underreview_status]').val(underreview_status);
	$(obj).addClass('tab-li-click');
	$(obj).siblings().removeClass('tab-li-click');
	$(".checkAll").attr("checked",false);
	
	getOperation(status);	
	initData(0);
	if($(".toggleButton").attr("refstatus") != "1"){
		$(".detailInfo").show();
	}
}

function orderBack(obj){
	orderBackObj = obj;
	orderBackCode = $(obj).attr("orders_code");
	$("#orderBackConfirmDialog").dialog("open");
};

function orderStop(obj){
	orderStopObj = obj;
	orderStopCode = $(obj).attr("orders_code");
	$("#orderStopConfirmDialog").dialog("open");
};
//获取操作
function getOperation(status){
	
	if(status==1 ||status==2 ||  status===0||  status===4){
		$('.order-operation').show();
		var options = '';
		loading();
		$.ajax({
			type: "POST",
			async: false,
			dataType: "json",
			url: "/merchant/orders/get-operation", //请求的处理url
			data:{'status':status},
			success: function(json) {
				if(json.ask){					
					$.each(json.result, function(key, val){						
						options += '<span class="button-2 batchProcess bold" status="'+key+'">'+val+'</span>';	
					});					
				}
				
				closeLoading();
			}
		});
		$('#operation').html(options);
		$(".batchProcess").click(function(){
			myConfirm(this);
		});
	}else{
		$('.order-operation').hide();
	}
}

function myConfirm(obj){
	if($(".checked:checked").length==0){
		$('#messageDialog').html("You must select at least one line").dialog("open");
		return;
	}
	$("#confirmDialog").dialog({
		autoOpen:false,
		modal:true,
		show:"slide",
		buttons:{
			"confirm":function(){
				$(this).dialog("close");
				submitBatch(obj);
			},
			"cancel":function(){
				$(this).dialog("close");
			}
		}
	});
	$("#confirmDialog").dialog("open");
}

function orderBackDo(obj,code__){
	
	var batchStatus =  1;
	var orderids = [code__];
	
	ajax_op(orderids,1,false);	
}

function orderStopDo(obj,code__){
	
	var batchStatus =  1;
	var orderids = [code__];
	
	ajax_op_stop(orderids,1,false);	
}

function submitBatch(obj,unCheckPlan){
	
	var batchStatus =  $(obj).attr("status");
	var orderids = [];
	$('input:checkbox[name="orderids"][checked]').each(function(i){
		orderids[i]=$(this).val();		
    });	
	ajax_op(orderids,batchStatus,unCheckPlan);
	
}
/*
	orderids 订单orders_code数组
	batchStatus 将要修改成的状态
	unCheckPlan 检测套餐
	enforce 强制扣费
*/
function ajax_op(orderids,batchStatus,unCheckPlan,enforce){
	if(enforce!=undefined){
		if(!window.confirm("are you sure charge from you account anyway[first month free]?")){
			return false;
		}
	}
	if(batchStatus==3){
		unCheckPlan = true;
	}
	loading();
	var tip = '';
	$.ajax({
			type: "POST",
			async: false,
			dataType: "json",
			url: "/merchant/orders/edit-status", //请求的处理url
			data:{'orderids':orderids,'batchStatus':batchStatus,'unCheckPlan':unCheckPlan,'enforce':enforce},
			success: function(json) {
				closeLoading();
				if(json==null){					
					return;
				}
				var alertReturn = false;
				if(json.ask){					
					if(enforce){
						$.each(json.result,function(k,v){							
							if(v.err_type!='undefined'){
								var link = "";
								if(v.err_type=="balance"){
									link = v.msg+"<a href='/merchant/my-account/deposit' style='color:red;margin-left:8px;'>click here<a>";
								}else if(v.err_type=="stock"){
									link =v.msg;
								}else{
									link =v.msg;
								}
								enforceTip(''+v.orders_code+'&nbsp;&nbsp;&nbsp;&nbsp;'+link);
								 $("#"+v.orders_code).html('<td style="width:25%;border:1px solid #cccccc;text-align:center">'+v.orders_code+'</td><td style="width:75%;border:1px solid #cccccc">'+link+'</td>');
							}else{
								enforceTip(''+v.orders_code+'&nbsp;&nbsp;&nbsp;&nbsp;'+v.msg);
								$("#"+v.orders_code).html('<td style="width:25%;border:1px solid #cccccc;text-align:center">'+v.orders_code+'</td><td style="width:75%;border:1px solid #cccccc">'+v.msg+'</td>');
							}
							
						});
					}else{
						
						tip = '<table style="border:1px solid #cccccc"><tr style="background:#FF870C"><td style="width:25%;border:1px solid #cccccc;text-align:center">Order Code</td> <td style="width:75%;border:1px solid #cccccc;text-align:center">Message</td></tr>';
						$.each(json.result,function(k,v){
							/*if(typeof v.alert != "undefined"){
								$("#checkPlanDialog").html(v.msg+",continue?").dialog("open");
								alertReturn = true;
							}*/
							if(v.err_type!='undefined'){
								var link = "";
								if(v.err_type=="balance"){
									link = v.msg+"<a href='/merchant/my-account/deposit' style='color:red;margin-left:8px;'>click here<a>";

								}else if(v.err_type=="stock"){
									link =v.msg;
								}else{
									link =v.msg;
								}
								tip += '<tr id="'+v.orders_code+'"><td style="width:25%;border:1px solid #cccccc;text-align:center">'+v.orders_code+'</td><td style="width:75%;border:1px solid #cccccc">'+link+'</td></tr>';
							}else{
								tip += '<tr id="'+v.orders_code+'"><td style="width:25%;border:1px solid #cccccc;text-align:center">'+v.orders_code+'</td><td style="width:75%;border:1px solid #cccccc">'+v.msg+'</td></tr>';
							}
	
						});
						tip += '</table>';
						$('#statusDialog').html(tip);
						$('#statusDialog').dialog("open");
					}
					
				}
				if(alertReturn){
					return;
				}
				$(".checkAll").attr("checked",false);
				initData(paginationCurrentPage);
			}
	});
}



function ajax_op_stop(orderids,batchStatus,unCheckPlan,enforce){
	if(enforce!=undefined){
		if(!window.confirm("are you sure charge from you account anyway[first month free]?")){
			return false;
		}
	}

	loading();
	var tip = '';
	$.ajax({
			type: "POST",
			async: false,
			dataType: "json",
			url: "/merchant/orders/stop", //请求的处理url
			data:{'orderids':orderids},
			success: function(json) {
				closeLoading();
				if(json==null){					
					return;
				}
				var alertReturn = false;
				if(json.ask){	
				    alert("Success.");
					$(".checkAll").attr("checked",false);
				    initData(paginationCurrentPage);
				}else{
				   alert("Fail.");
				   return;
				}
				if(alertReturn){
					return;
				}
				
			}
	});
}



//操作提示
function enforceTip(tip) {
    $('<div title="Tip"><p align="center">' + tip + '</p></div>').dialog({
        modal: true,
        buttons: {
            'close': function() {
                $(this).dialog("close");
            }
        }
    });
}

function clear(){
	
}

</script>
<style>
.input-width{width:120px;}
</style>
<div class="position"><a href='/default/index'><{$languages['HOME']}></a> &gt; <a href='/merchant/my-account'><{$languages['MERCHANT_CENTER']}></a>  &gt; <{$languages['OPERATION']}> &gt; <{$languages['ORDER_LIST']}></div>

<h4><{$languages['ORDER_LIST']}></h4>
<div style="color:red;" id="message"></div>
<div id="search" style="margin-top:15px;margin-bottom:15px;">
<form id="search-form" name="search-form" method="post" action="">
	<div>
		<{$languages.ORDERNO}>: <input type="text" id="orders_code_sch" name="orders_code_sch" class="input-width" />	&nbsp;&nbsp;
        <{$languages.REFERENCE_NO}>: <input type="text" id="ReferenceNo" name="ReferenceNo" class="input-width" />&nbsp;&nbsp;
        <{$languages.CREATED_DATE}>: <input type="text" id="createTime" name="createTime" class="input-width" />
		<input type="hidden" name="status" id="status" value="<{$status}>" />
		<input type="hidden" name="underreview_status" id="underreview_status" value="0" />
		
	</div>
	<div style="padding:10px 0 0 0;">
        <{$languages.SHIPPING_METHOD}>:
		<select  id="shipping_method" onchange="search()" name='shipping_method'>
		 <option value="">All</option>
		<{foreach from=$shipType item=obj key=key name=obj}>
        	<option value="<{$obj.st_code}>"><{$obj.st_code}></option>			
		<{/foreach}>
		</select>&nbsp;&nbsp;		
	</div>
	<div style="margin-top:15px;">
		<span class="button-2" onclick="search()"><{$languages.SEARCH}></span>
        <span class="button-2 toggleButton" refstatus="1" fold='<{$languages['FOLD']}>' unfold='<{$languages['UNFOLD']}>'><{$languages['FOLD_UNFOLD']}></span>

    </div>
<p> 

</form>
</div>

<div class="info-content">
		<div class="info-content-menu radiu">
			<ul class="bgc"><!-- tab-li-click -->
                <{foreach from=$orderStatus key=k item=val}>
				<li class="tab-li <{if $k==1}>tab-li-click<{/if}>"
                <{if $k==3}>
                onclick="tabSelect(this,4,1)
                <{elseif $k==4}>
                onclick="tabSelect(this,3)
                <{else}>
                    onclick="tabSelect(this,<{$k}>)
                <{/if}>

                "> <{$val}>(<span id="status<{$k}>"></span>)</li>
                <{/foreach}>
			</ul>
		</div>
		
</div>

<div class="order-operation" style="width:100%" id="operation">
		
</div>

<div class="tab-div row" style="OVERFLOW-X:scroll; width:745px;">
	<div class="row height25 row-header" style="width:900px;">
		
	</div>

	<div id="order-list" style="width:900px;">  </div>

</div>
<div class="pagination" style="padding-top:10px"></div>
<div id="messageDialog" style="display:none;" title="message">
	
</div>
<div id="statusDialog" style="display:none;" title="message">
	
</div>
<div id="confirmDialog" style="display:none;" title="Tip">
	Are you sure?
</div>
<div id="checkPlanDialog" style="display:none;" title="Tip">
	
</div>

<div id="orderBackConfirmDialog" style="display:none;" title="Tip">
	Are you sure?
</div>

<div id="orderStopConfirmDialog" style="display:none;" title="Tip">
	Are you sure Stop?
</div>

<div style="display:none;">
<div id="order-header-content-0">
        <div style="width:50px;" class="cell"><input type="checkbox" onclick="checkAll(this)" class="checkAll">&nbsp;
        </div>
        <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
        <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
        <div style="width:150px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
        <div style="width:150px;" class="cell"><{$languages.COUNTRY}></div>
        <div style="width:150px;" class="cell"><{$languages.CREATED_DATE}></div>
        <div style="width:100px;" class="cell no-background"><{$languages.ACTIONS}></div>
</div>
    <div id="order-header-content-1">
            <div style="width:50px;" class="cell"><input type="checkbox" onclick="checkAll(this)" class="checkAll">&nbsp;
            </div>
            <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
            <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
            <div style="width:100px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
            <div style="width:150px;" class="cell"><{$languages.COUNTRY}></div>
            <div style="width:100px;" class="cell"><{$languages.ORDER_PRICE}></div>
            <div style="width:150px;" class="cell"><{$languages.CREATED_DATE}></div>
            <div style="width:50px;" class="cell no-background"><{$languages.ACTIONS}></div>
    </div>

    <div id="order-header-content-4">
            <div style="width:50px;" class="cell"><input type="checkbox" onclick="checkAll(this)" class="checkAll">&nbsp;
            </div>
            <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
            <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
            <div style="width:100px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
            <div style="width:150px;" class="cell"><{$languages.CREATED_DATE}></div>
            <div style="width:150px;" class="cell"><{$languages.LAST_DATE}></div>
            <div style="width:100px;" class="cell"><{$languages.ISSUETYPE}></div>
            <div style="width:50px;" class="cell no-background"><{$languages.ACTIONS}></div>
    </div>

    <div id="order-header-content-3">
            <div style="width:50px;" class="cell"><input type="checkbox" onclick="checkAll(this)" class="checkAll">&nbsp;
            </div>
            <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
            <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
            <div style="width:150px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
            <div style="width:150px;" class="cell"><{$languages.COUNTRY}></div>
            <div style="width:150px;" class="cell"><{$languages.ORDER_PRICE}></div>
            <div style="width:100px;" class="cell no-background"><{$languages.ACTIONS}></div>
    </div>

    <div id="order-header-content-5">
            <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
            <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
            <div style="width:150px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
            <div style="width:100px;" class="cell"><{$languages.COUNTRY}></div>
            <div style="width:150px;" class="cell"><{$languages.TRUCKINGNO}></div>
            <div style="width:150px;" class="cell"><{$languages.SHIPDATE}></div>
            <div style="width:50px;" class="cell2 no-background"><{$languages.ACTIONS}></div>
    </div>

    <div id="order-header-content-6">
            <div style="width:150px;" class="cell"><{$languages.ORDERNO}></div>
            <div style="width:150px;" class="cell"><{$languages.REFERENCE_NO}></div>
            <div style="width:100px;" class="cell"><{$languages.SHIPPING_METHOD}></div>
            <div style="width:150px;" class="cell"><{$languages.TRUCKINGNO}></div>
            <div style="width:150px;" class="cell"><{$languages.SHIPDATE}></div>
            <div style="width:150px;" class="cell"><{$languages.DELIVERDATE}></div>
            <div style="width:50px;" class="cell2 no-background"><{$languages.ACTIONS}></div>
    </div>

</div>